package com.sbpm.crmbpm.shared.data.client;

import com.sbpm.crmbpm.shared.data.AbstractEntity;
import com.sbpm.crmbpm.shared.data.interaction.Interaction;
import com.sbpm.crmbpm.shared.data.product.ProductDefinition;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@SequenceGenerator(name="companySeq", sequenceName="COMPANY_SEQ")
@Table( name = "COMPANY" )
public class Company implements Serializable, AbstractEntity

{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="companySeq")
    @Column( name = "COMPANY_ID" )
    private Long id;

    @Enumerated( EnumType.STRING )
    @Column( name = "COMPANY_TYPE" )
    private CompanyType type;

    @Column( name = "INN" )
    private String inn;

    @Column( name = "OGRN" )
    private String ogrn;

    @Column( name = "KPP" )
    private String kpp;

    @Column( name = "NAME" )
    private String name;

    @Column( name = "LEGAL_NAME" )
    private String legalName;

    @Column( name = "SEGMENT" )
    @Enumerated( EnumType.STRING )
    private Segment segment;

    @OneToMany( fetch = FetchType.LAZY, mappedBy = "owner" )
    private List<ProductDefinition> productDefinitions = new ArrayList<ProductDefinition>();

    @OneToMany( fetch = FetchType.LAZY, mappedBy = "company" )
    private List<PersonCompanyRel> persons = new ArrayList<PersonCompanyRel>();

    @OneToMany( fetch = FetchType.LAZY, mappedBy = "company")
    private Set<Address> addresses = new HashSet<Address>();

    @ManyToMany( fetch = FetchType.LAZY, mappedBy = "companies" )
    private List<Interaction> interactions = new ArrayList< Interaction >();

    public Set< Address > getAddresses()
    {
        return addresses;
    }

    public void setAddresses( Set< Address > addresses )
    {
        this.addresses = addresses;
    }

    public List< PersonCompanyRel > getPersons()
    {
        return persons;
    }

    public void setPersons( List< PersonCompanyRel > persons )
    {
        this.persons = persons;
    }

    public List< Interaction > getInteractions()
    {
        return interactions;
    }

    public void setInteractions( List< Interaction > interactions )
    {
        this.interactions = interactions;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public CompanyType getType() {
        return type;
    }

    public void setType(CompanyType type) {
        this.type = type;
    }

    public String getInn() {
        return inn;
    }

    public void setInn(String inn) {
        this.inn = inn;
    }

    public String getOgrn() {
        return ogrn;
    }

    public void setOgrn(String ogrn) {
        this.ogrn = ogrn;
    }

    public String getKpp() {
        return kpp;
    }

    public void setKpp(String kpp) {
        this.kpp = kpp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLegalName() {
        return legalName;
    }

    public void setLegalName(String legalName) {
        this.legalName = legalName;
    }

    public Segment getSegment() {
        return segment;
    }

    public void setSegment(Segment segment) {
        this.segment = segment;
    }

    public List< ProductDefinition > getProductDefinitions()
    {
        return productDefinitions;
    }

    public void setProductDefinitions( List< ProductDefinition > productDefinitions )
    {
        this.productDefinitions = productDefinitions;
    }
}
